package com.yonder.detail;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.yonder.summary.Summary;

@AuthorizeInstantiation({ "GOD", "ADMIN" })
public class Detail extends WebPage {

	/**
	 * 
	 * 
	 */
	private static final long serialVersionUID = 3069120261412213321L;
	private DetailsModel detailModel = new DetailsModel();

	public Detail(PageParameters parameters) {
		super(parameters);
		add(new FeedbackPanel("feedback"));
		final List<String> TYPES = Arrays.asList(new String[] { "Male", "Female" });
		Form<DetailsModel> detailForm = new Form<DetailsModel>("detailForm", new CompoundPropertyModel<DetailsModel>(
				detailModel));
		final TextField<String> tName = new TextField<String>("name");
		tName.setRequired(true);
		final RadioChoice<String> radioGender = new RadioChoice<String>("gender", TYPES);
		radioGender.setRequired(true);
		final List<String> CITY = Arrays.asList(new String[] { "Iasi", "Cluj", "Amsterdam" });
		final DropDownChoice<String> cityDrop = new DropDownChoice<String>("city", CITY);
		cityDrop.setRequired(true);

		final DateTextField df = new DateTextField("birthdate", "dd/MM/yyyy");
		DatePicker datePicker = new DatePicker();
		datePicker.setShowOnFieldClick(true);
		df.setRequired(true);
		df.add(datePicker);
		detailForm.add(tName);
		detailForm.add(radioGender);
		detailForm.add(cityDrop);
		detailForm.add(df);
		Button submitButton = new Button("submitButton") {
			/**
			 * 
			 */
			private static final long serialVersionUID = -8528965043663341462L;

			@Override
			public void onSubmit() {				
				getSession().setAttribute("details", detailModel);				
				setResponsePage(Summary.class);
			}
		};
		detailForm.add(submitButton);
		add(detailForm);
	}
}
